/**
 * 功能描述 导航栏
 */

define(function (require, exports, module) {
	var Subnav = require("subnav");
	var aw = require("ajaxwrapper")
	var store =require("store");
	var user = require("store").get("user");
	var checkinfile = require("../store/plancheckoutsettlementStore");
	
    var instance = {
        initComponent:function (params,widget){
        	var subnav=new Subnav({
        		parentNode:".J-subnav",
        		model:{
            		title:"团队退房结算单",
            		items:[{
            			id:"servicepoint",
            			type:"buttongroup",
//            			url:"api/servicepoint/operableservicepoints",
            			tip:"服务点",
						keyField :"pkServicePoint",
						valueField :"name",
						items:user.privateServicePoints,
//            			lazy:true,
            			params:{
							fetchProperties:"pkServicePoint,name"
						},
            			handler:function(key,element){
            				widget.get("grid").refresh();
            			}
            		},{
            			 id:"CheckInStatus",
			   			 tip:"全部",
			   			 type:'buttongroup',
						 items:[{
								key :"NoConfirm",
								value:"待确认"
						 },{
								key :"Confirm",
								value:"已确认"
						 }],
            			handler:function(key,element){
    						widget.get("grid").refresh();
    					}
            		},{
            			id:"checkOutDate",
						tip:"退房日期",
						type:"daterange",
						ranges:{
					 		"本月": [moment().startOf("month"), moment().endOf("month")],
					 		"上月": [moment().subtract(1,"months").startOf("month"), moment().subtract(1,"months").endOf("month")],
					 		"本周": [moment().startOf("week"), moment().endOf("week")],
					 		"上周": [moment().subtract(1,"week").startOf("week"), moment().subtract(1,"week").endOf("week")]
						},
						handler : function(time){
							 widget.get("grid").refresh();
						}
            		},{
        				id: "return",
        				type: "button",
						text: "返回",
						show: false,
						handler: function(){
							widget.detail = false;
							widget.show([".J-grid"]).hide([".J-editgrid",".J-form",".J-endGrid",".J-total",".J-detailForm",".J-alltotal",".J-allform",".J-onCreditForm"]);
							widget.get("subnav").hide(["return","print","totalprint"]).show(["paymentMethod","checkOutDate","CheckInStatus","servicepoint"]);
						}
        				
        			},{
        				id: "print",
        				type: "button",
						text: "个人明细打印",
						show: false,
						handler: function(){
							widget.handler.print(widget);
						}
        			},{
        				id: "totalprint",
        				type: "button",
						text: "结算单打印",
						show: false,
						handler: function(){
							var teamType = widget.get("teamType");
							var idata = {};
							
							idata["teamType"] = teamType;
							var endGrid = widget.get("endGrid").getData();
							var personal = [];
							for(var i=0;i<endGrid.length;i++){
								var personalObj = {};
								personalObj.name = endGrid[i].signUpRegister.personalInfo.name;
								personalObj.code = endGrid[i].roomRegister.room.code;
								personal.push(personalObj);
							}
							idata["endGrid"] = personal;
							if(teamType == "直属入住联盟"){
								
								idata["tatalGrid"] = widget.get("totalGrid").getData();
								
								
								var allform = widget.get("allform");
								var allFormData = allform.getData();
								idata.destination = allFormData["allianceConfirm.groupReserve.planItemGroup.planItem.destination.name"];
								idata.signUpNumber = allFormData["signUpNumber"];
								idata.checkInDate = allFormData["allianceConfirm.groupReserve.checkInDate"];
								idata.checkOutDate = allFormData["allianceConfirm.groupReserve.checkOutDate"];
								idata.operatorName = allFormData["allianceSettlement.operator.name"];
								idata.statementDate = allFormData["allianceSettlement.settlementDate"];
							}else{
								idata["tatalGrid"] = widget.get("totalGrid").getData();
								
								var allform = widget.get("form");
								var allFormData = allform.getData();
								idata.destination = allFormData["destinationName"];
								idata.signUpNumber = allFormData["signUpNum"];
								idata.checkInDate = allFormData["checkInDate"];
								idata.checkOutDate = allFormData["checkOutDate"];
								idata.operatorName = allFormData["operatorName"];
								idata.statementDate = allFormData["statementDate"];
							}
							
							window.open("assets/eling/elcms/travel/plancheckoutsettlement/src/plancheckoutprint.html?obj="+JSON.stringify(idata));
						}
        			},{

        				id: "paymentMethod",
        				type: "buttongroup",
        				tip:"结算方式",
						  items: [{
					          key: "all",
					          value: "全部"
					        }, {
					          key: "Cash",
					          value: "现金"
					        }, {
						      key: "WipeCard",
						      value: "刷卡"
						    }, {
							  key: "Transfer",
							  value: "转账"
							}, {
							  key: "OnCredit",
							  value: "挂账"
							}],
						handler: function(key){
							widget.get("grid").refresh();
						}
        			}]
        		}
        	});
        	widget.set("subnav",subnav);

        }
    };
    module.exports = instance;
});
